﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CJJCH.Web
{
    public partial class LeftMenu : System.Web.UI.UserControl
    {
        CJJCH.BLL.T_NET_MenuSecond bll_second = new CJJCH.BLL.T_NET_MenuSecond();
        CJJCH.BLL.T_NET_MenuThird bll_third = new CJJCH.BLL.T_NET_MenuThird();
        protected void Page_Load(object sender, EventArgs e)
        { 
            if (!IsPostBack)
            {
                RepeaterDataBind();
            }
        }

        private int _firstId;

        public int FirstId
        {
            get { return _firstId; }
            set { _firstId = value; }
        }

        private int _secondId;

        public int SecondId
        {
            get { return _secondId; }
            set { _secondId = value; }
        }

        private int _thirdId;

        public int ThirdId
        {
            get { return _thirdId; }
            set { _thirdId = value; }
        }

        private string _keyword;

        public string Keyword
        {
            get { return _keyword; }
            set { _keyword = value; }
        }

        protected void RepeaterDataBind()
        {
            if (FirstId >0)
            {
                switch (FirstId)
                {
                    case 1:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header1.gif";
                        break;
                    case 2:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header2.gif";
                        break;
                    case 3:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header4.gif";
                        break;
                    case 4:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header6.gif";
                        break;
                    case 5:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header7.gif";
                        break;
                    case 6:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header8.gif";
                        break;
                    case 7:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header9.gif";
                        break;
                    case 8:
                        this.imgLeftTop.ImageUrl = "~/Image/SubBodyLeft_header3.gif";
                        break;
                    default:
                        Response.Redirect("~/error.aspx");
                        break;
                }
            }
            else
            {
                Response.Redirect("~/error.aspx");
            }

            IList<CJJCH.Model.T_NET_MenuSecond> list = new List<CJJCH.Model.T_NET_MenuSecond>();
            list = bll_second.GetMenuSecondList(0, FirstId);
            this.rptMenu.DataSource = list;
            this.rptMenu.DataBind();
        }

        protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            ((HyperLink)e.Item.FindControl("lnkMenu")).Text = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
            if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName.Length > 9)
            {
                ((HyperLink)e.Item.FindControl("lnkMenu")).Style.Add("font-size", "13px");
            }
            //((HyperLink)e.Item.FindControl("lnkMenu")).ToolTip = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
            if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).HaveChild && ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID != 1 && ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID != 8)
            {
                if (Request.QueryString["typename"] != null)
                {
                    if (Convert.ToInt32(Request.QueryString["thirdid"]) == 0 && ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() == SecondId.ToString() && ThirdId == 0)
                    {
                        ((System.Web.UI.HtmlControls.HtmlControl)e.Item.FindControl("divMenu")).Attributes.Add("class", "Header_TitleCur1");
                    }
                }
                Repeater rptSubMenu = (Repeater)e.Item.FindControl("rptSubMenu");
                IList<CJJCH.Model.T_NET_MenuThird> list = new List<CJJCH.Model.T_NET_MenuThird>();
                list = bll_third.GetThird(((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID, "");
                if (list.Count > 0)
                {
                    rptSubMenu.DataSource = list;
                    rptSubMenu.DataBind();
                }
            }
            else
            {
                HtmlGenericControl divSubMenu = (HtmlGenericControl)e.Item.FindControl("divSubMenu");
                divSubMenu.Style.Add("display", "none");
                switch (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID)
                {
                    case 1:
                        if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).HaveChild)
                        {
                            ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ApplicationProcedures.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        }
                        else
                        {
                            ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/NotePage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        }
                        break;
                    case 2:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 3:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 4:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ExpertAppraisal.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 5:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 6:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 7:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/OnLineRegis.aspx?firstid=" + FirstId.ToString() + "&secondid=" +((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 8:
                        ((HyperLink)e.Item.FindControl("lnkMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    default:
                        break;
                }
                if (SecondId > 0)
                {
                    if (ThirdId == 0 && ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() == SecondId.ToString())
                    {
                        ((System.Web.UI.HtmlControls.HtmlControl)e.Item.FindControl("divMenu")).Attributes.Add("class", "Header_TitleCur1");
                    }
                }
                else
                {
                    Response.Redirect("~/error.aspx");
                }
            }
        }

        protected void rptSubMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((HyperLink)e.Item.FindControl("lnkSubMenu")).Text = "·" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).MenuName;
                if (((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).MenuName.Length > 8)
                {
                    ((HyperLink)e.Item.FindControl("lnkSubMenu")).Style.Add("font-size", "12px");
                }
                switch (((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).MenuSecond.MenuTypeID)
                {
                    case 1:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/NotePage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    case 2:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    case 3:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    case 4:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/ExpertAppraisal.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() + "&thirdid=0";
                        break;
                    case 5:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    case 6:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    case 7:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/OnLineRegis.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    case 8:
                        ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "~/ListPage.aspx?firstid=" + FirstId.ToString() + "&secondid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).SecondID.ToString() + "&thirdid=" + ((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() + "";
                        break;
                    default:
                        break;
                }
                if (((CJJCH.Model.T_NET_MenuThird)e.Item.DataItem).ID.ToString() == ThirdId.ToString())
                {
                    HtmlGenericControl liSubMenu = (HtmlGenericControl)e.Item.FindControl("liSubMenu");
                    liSubMenu.Attributes.Add("class", "SubmenuCur");
                }               
            }
        }
    }
}